import FViewModule from "../../Libs/Framework/Support/FViewModule";
import { GameDataManager } from "../../Libs/Framework/Managers/GameDataManager";
const { ccclass, property } = cc._decorator;
@ccclass
export default class PlayerInfo extends FViewModule {
    private _nickname : cc.Label = null
    private _fangka : cc.Label = null
    private _uid : cc.Label = null

    
    @property({serializable:true})
    private upspeed : number = 0

    private _speed : number = 0;

    public onLoad() : void {
        this._nickname = this.node.getChildByName("nickname").getComponent(cc.Label)
        this._fangka = this.node.getChildByName("fangka").getComponent(cc.Label)
        this._uid = this.node.getChildByName("uid").getComponent(cc.Label)

        this._nickname.string = ""
        this._fangka.string = ""
        this._uid.string = ""
        
        this.node.opacity = 0
        this.node.y = this.node.parent.height / 2 + this.node.height / 2
    }

    public showViews(){
        let action = cc.spawn(
            cc.fadeTo(0.3,255),
            cc.moveTo(0.5,cc.p({x:0,y:this.node.parent.height / 2 - this.node.height / 2}))
        )
        this.node.runAction(action)
    }

    public updateInfo(){
        this._nickname.string = GameDataManager.game.nickname
        this._fangka.string = String(GameDataManager.game.fangka)
        this._uid.string = "ID:" +String(GameDataManager.game.playerId)
    }

    public update() : void {
        if(CC_EDITOR)return
        if(this.upspeed == this._speed){
            this._speed = 0;
            this.updateInfo()
            return
        }
        this._speed++

    }
}